var express = require('express');
var router = express.Router();
var User = require("./../src/db/user");
var Message = require("./../src/db/message");




//注册
router.post('/user/signup', function(req, res, next) {
	const _user = req.body;
	User.signup(_user).then(function(reslut){
		res.json(reslut);
	},function(erro){
		res.json(erro);
	})
	

});
//登录
router.post('/user/signin', function(req, res, next) {
	const _user = req.body;
	User.signin(_user).then(function(reslut){
		req.session.user = reslut.data;
		res.json(reslut);
		console.log(req.session.user)
	},function(error){
		res.json(error);
	})
	

});
//退出登录

router.post('/user/signout', function(req, res, next) {
	console.log(req.session.user);
	req.session.user = null;
	res.send({
		code:1,
		message:"退出成功"
	})
});

//获取历史消息
router.post('/message/history', function(req, res, next) {
	Message.history(req.body).then(function(reslut){
		res.json(reslut);
	},function(error){
		res.json(error);
	});
	
});

//文件上传
router.post('/fileup', function(req, res, next) {
	
	res.json({"success":1});	
	Message.fileUp({req:req}).then(function(data){
		console.log(data);
	},function(error){
		console.log(error);
	});
});


module.exports = router;